package com.handpay.nocardpay.baselibrary.main.widget;

import com.handpay.nocardpay.baselibrary.R;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class PayChannelInfo {
    public static final String UNIPAY_CODE = "6";                     //银联支付
    public static final String ALIPAY_CODE = "8";                     //支付宝正扫支付
    public static final String WECHATPAY_CODE = "4";               //微信正扫支付
    public static final String UNIPAY_QUICK_CODE = "7";         //银联快捷

    public static final String QQ_PAY_CODE = "9";                     //QQ钱包
    public static final String JD_PAY_CODE = "10";                     //京东钱包
    public static final String UNIPAY_SCANNER_CODE = "11";     //银联扫码
    public static final String QUICK_PASS_CODE = "12";             //云闪付

//    刷卡收款：1
//    支付宝反扫：2
//    微信反扫：3
//    扫码支付：5
//    黄颜色为无卡APP新功能返回
//    银联在线：6；
//    支付宝正扫：8；
//    微信正扫：4；
//    银联快捷：7；
//    QQ钱包：9；
//    京东钱包：10；
//    银联扫码：11；
//    云闪付：12；
//    Apple Pay：13
    public String itemId;
    public String title;
    public int[] iconResId;
    public boolean isSelected, isEnable;
    private static HashMap<String, PayChannelInfo> mPayMaps;

    public PayChannelInfo(String itemId, String title, int[] iconResId,  boolean isEnable) {
        super();
        this.itemId = itemId;
        this.title = title;
        this.iconResId = iconResId;
        this.isSelected = false;
        this.isEnable = isEnable;
    }

    public static HashMap<String, PayChannelInfo> getPayChannelInfos() {
        if (mPayMaps == null) {
            mPayMaps = new HashMap<String, PayChannelInfo>();
            mPayMaps.put(UNIPAY_CODE, new PayChannelInfo(UNIPAY_CODE, "银联在线", new int[]{R.drawable.home_icon_unipay},true));
            mPayMaps.put(ALIPAY_CODE, new PayChannelInfo(ALIPAY_CODE, "支付宝收款", new int[]{R.drawable.home_icon_alipay},true));
            mPayMaps.put(WECHATPAY_CODE, new PayChannelInfo(WECHATPAY_CODE, "微信收款", new int[]{R.drawable.home_icon_wechatpay},true));
            mPayMaps.put(UNIPAY_QUICK_CODE, new PayChannelInfo(UNIPAY_QUICK_CODE, "银联快捷", new int[]{R.drawable.home_icon_unipay_quick},  false));

            mPayMaps.put(QQ_PAY_CODE, new PayChannelInfo(QQ_PAY_CODE, "QQ钱包", new int[]{R.drawable.home_icon_qq_pay},  false));
            mPayMaps.put(JD_PAY_CODE, new PayChannelInfo(JD_PAY_CODE, "京东钱包", new int[]{R.drawable.home_icon_jd_pay},  false));
            mPayMaps.put(UNIPAY_SCANNER_CODE, new PayChannelInfo(UNIPAY_SCANNER_CODE, "银联二维码", new int[]{R.drawable.home_icon_unipay_scanner},  false));
            mPayMaps.put(QUICK_PASS_CODE, new PayChannelInfo(QUICK_PASS_CODE, "云闪付", new int[]{R.drawable.home_icon_quick_pass},  false));
        }
        return mPayMaps;
    }

    public static void release() {
        if (mPayMaps != null) {
            mPayMaps = null;
        }
    }

    public static boolean setPayChannelInfoSelectByTag(String tag) {
        HashMap<String, PayChannelInfo> mPayMaps = getPayChannelInfos();
        Iterator iter = mPayMaps.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry<String, PayChannelInfo> entry = (Map.Entry<String, PayChannelInfo>) iter.next();
            String key = entry.getKey();
            PayChannelInfo val = entry.getValue();
            if (key.equals(tag)) {
                val.isSelected = true;
            } else {
                val.isSelected = false;
            }
        }
        return true;
    }
}
